<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TestApi</title>
</head>
<body>
    <input type="text" id="message">
    <button id="sendButton">发送</button>

    <script>
        let websocket = new WebSocket("ws://localhost:8080/test");

        websocket.onopen = function(){
            console.log("open...");
        }

        websocket.onclose = function(){
            console.log("close...");
        }

        websocket.onerror = function(){
            console.log("error...");
        }

        websocket.onmessage = function(e){
            console.log(e.data);
        }

        let message = document.getElementById("message");
        document.getElementById("sendButton").onclick = function(){
            console.log(message.value);
            websocket.send(message.value);
        }
    </script>
</body>
</html>